package service.impl;

import mapper.SupplierMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import entity.Supplier;
import service.SupplierService;
import utils.Page;

import java.util.List;

@Service("supplierService")
@Transactional
public class SupplierServiceImpl implements SupplierService {

    @Autowired
    private SupplierMapper supplierMapper;
    @Override
    public List<Supplier> getSuppliers() {

        return supplierMapper.getSupplier();
    }

    @Override
    public int deleteSuppliers(Integer id) {
        return supplierMapper.deleteSuppliers(id);
    }

    @Override
    public boolean updateSupplier(Supplier supplier) {
        return supplierMapper.updateSupplier(supplier)>0;
    }

    @Override
    public Page<Supplier> getPage(Supplier supplier, Integer pageNo, Integer pageSize) {
        Page<Supplier> page = new Page<Supplier>();
        page.setPageSize(pageSize);
        // 查询总数，计算总页数
        Integer count = supplierMapper.count(supplier);
        page.setTotalCount(count);
        page.setPageNo(pageNo);
        List<Supplier> data = supplierMapper.getPage(supplier, page.offset(), page.getPageSize());
        page.setData(data);
        return page;
    }


    @Override
    public Supplier getById(Long id) {
        return supplierMapper.getById(id);
    }

    @Override
    public boolean insertSupplier(Supplier supplier) {
        return supplierMapper.insertSupplier(supplier)>0;
    }

    @Override
    public Supplier getSupCode(String supCode) {
        return supplierMapper.getSupCode(supCode);
    }
}
